package com.example.administrator.orchardeveryday.ui;

import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.RadioGroup;

import com.example.administrator.orchardeveryday.BaseApp;
import com.example.administrator.orchardeveryday.R;
import com.example.administrator.orchardeveryday.fragments.CarFragment;
import com.example.administrator.orchardeveryday.fragments.FruitFragment;
import com.example.administrator.orchardeveryday.fragments.HomeFragment;
import com.example.administrator.orchardeveryday.fragments.KindFragment;
import com.example.administrator.orchardeveryday.fragments.MineFragment;
import com.example.administrator.orchardeveryday.utils.AppManager;
import com.example.administrator.orchardeveryday.utils.FragmentTabUtils;

import java.util.ArrayList;

public class MainActivity extends BaseActivity implements FragmentTabUtils.OnRgsExtraCheckedChangedListener{


    private long time;
    private ArrayList<Fragment> fragments=new ArrayList<>();
    private RadioGroup radioGroup;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        getSupportActionBar().hide();

    }
    private void initView() {
        radioGroup= (RadioGroup) this.findViewById(R.id.activity_main_footer_rgs);
        fragments.add(new HomeFragment());
        fragments.add(new KindFragment());
        fragments.add(new MineFragment());
        fragments.add(new CarFragment());
        fragments.add(new FruitFragment());
        new FragmentTabUtils(getSupportFragmentManager(),fragments,R.id.activity_main_fragment_container,radioGroup,this);
    }
    @Override
    public void onBackPressed() {
        long currentTime = System.currentTimeMillis();
        if (currentTime - time > 1000) {
            time = currentTime;
            BaseApp.getInstance().showToast(getString(R.string.app_exit_msg));
        } else {
            AppManager.getAppManager().AppExit(BaseApp.getInstance());
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {


        return super.onOptionsItemSelected(item);
    }


    @Override
    public void OnRgsExtraCheckedChanged(RadioGroup radioGroup, int checkedId, int index) {

    }
}
